﻿using ST.Torch.WebApi.Core.Entities.System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ST.Torch.WebApi.Application.System.Dtos
{
	public class SYSMenuDto
	{
		/// <summary>
		/// 菜单名称
		/// </summary>
		[MaxLength(100)]
		public string Title { get; set; }
		/// <summary>
		/// 图标
		/// </summary>
		[MaxLength(100)]
		public string Icon { get; set; }

		/// <summary>
		/// 菜单路由地址
		/// </summary>
		[MaxLength(500)]
		public string Href { get; set; }
		/// <summary>
		/// 打开方式 _component
		/// </summary>
		[MaxLength(500)]
		public string OpenType { get; set; }

		/// <summary>
		///  0 菜单 1 页面 2按钮
		/// </summary>
		public MenuTypeEnum Type { get; set; }

		/// <summary>
		/// 是否隐藏
		/// </summary>
		public bool IsHide { get; set; }
		/// <summary>
		/// 上级id, Guid.Empty是顶级
		/// </summary>
		public Guid ParentId { get; set; }
		/// <summary>
		/// 节点语义ID  顶级父Id +.+级父Id+.+...+自己id 用与like 查询
		/// </summary>
		[Column(TypeName = "varchar(1000)")]
		public string CascadeId { get; set; }
        /// <summary>
        /// 权限标识
        /// </summary>
        [Column(TypeName = "varchar(100)")]
        public string PermissionId { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }
    }
	public class SYSMenuListDto: SYSMenuDto
	{
		public Guid Id { get; set; }
		public DateTime? CreateTime { get; set; }
		public DateTime? UpdateTime { get; set; }

		public string TypeStr { get; set; }

        //---
    }
    public class SYSMenuTreeListDto: SYSMenuListDto
    {
        
        public List<SYSMenuTreeListDto> children { get; set; }
        //public string TypeStr { get; set; }

        //public string title { get; set; }

        //---
    }
    public class SYSMenuTreeSelectListDto 
    {
		public Guid id { get; set; }
		public string title { get; set; }
		
		public bool @checked { get; set; }
		/// <summary>
		/// 是否展开
		/// </summary>
		public bool spread { get; set; }
        
        public List<SYSMenuTreeSelectListDto> children { get; set; }

		//public string title { get; set; }

		//---
	}

	public class LayuiMenuDto
    {
        public string id { get; set; }
        public string title { get; set; }
        public string icon { get; set; }
        public int type { get; set; }
        public string openType { get; set; }
        public string href { get; set; }
        public string permissionId { get; set; }
        
        public List<LayuiMenuDto> children { get; set; }

    }


    public class SYSMenuMapper : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            //0 菜单 1 页面 2按钮
            config.ForType<SYSMenu, SYSMenuListDto>()
                .Map(dest => dest.TypeStr, src => src.Type == MenuTypeEnum.Menu ? "菜单":( src.Type == MenuTypeEnum.Page ? "页面": "按钮"))
                ;
            //0 菜单 1 页面 2按钮
            config.ForType<SYSMenu, SYSMenuTreeListDto>()
                .Map(dest => dest.TypeStr, src => src.Type == MenuTypeEnum.Menu ? "菜单" : (src.Type == MenuTypeEnum.Page ? "页面" : "按钮"))
                ;
        }
      
    }


}
